// d:\byte\tiktok-applet-v3 - 智慧天气 - 家具\pages\conmment\conmment.js

const model = require('../../public/model/env.js');
const key = model.key();
const appid = model.appid();
// const user_icon = tt.getStorageSync('user_icon') || '';
const url = model.api_pro_url();
Page({
  data: {
    background: 'youjia',
    title: '评论区',
    logotext: '评论区',
    commentlist: [],
    user_commentlist: [],
  },

  onLoad: function () {
    this.get_commentlist();
    this.get_user_commentlist();
    // 页面加载,标题设置
    tt.setNavigationBarTitle({
      title: this.data.title,
    });
    tt.setNavigationBarColor({
      frontColor: '#ffffff',
      backgroundColor: '#000000',
    });
    // 页面加载,标题设置结束

  },
  get_commentlist() {
    const requestUrl = `${url}/index.php/api/comment_my.php`;

    const options = {
      url: requestUrl,
      data: {
        comment_id: '202506111202506111',
        key: key
      },
      method: 'POST',
      header: {
        'content-type': 'application/json'
      },
      dataType: 'json',
    };
    // console.log(options);
    tt.request({
      ...options,
      success: (res) => {
        const data = res.data;
        console.log(data);
        if (data.code == 200) {
          this.setData({
            commentlist: data.data
          });
          // tt.showToast({ title: res.data.message, icon: 'success', duration: 2000 });

        }
        else {
          tt.showToast({ title: res.data.message, icon: 'fail', duration: 2000 });
        }
      },
      fail: (err) => {
      }
    })

  },
  get_user_commentlist() {
    const requestUrl = `${url}/index.php/api/comment_list.php`;

    const options = {
      url: requestUrl,
      data: {
        // comment_id: '202506111202506111',
        app_id: appid,
        key: key
      },
      method: 'POST',
      header: {
        'content-type': 'application/json'
      },
      dataType: 'json',
    };
    console.log(options);
    tt.request({
      ...options,
      success: (res) => {
        const data = res.data;
        console.log(data);
        if (data.code == 200) {
          this.setData({
            user_commentlist: data.data
          });
          tt.showToast({ title: res.data.message, icon: 'none', duration: 2000 });


        }
        else {
          tt.showToast({ title: res.data.message, icon: 'fail', duration: 2000 });
        }
      },
      fail: (err) => {
      }
    })

  },

})